package eu.jpereira.trainings.designpatterns.structural.facade;

import eu.jpereira.trainings.designpatterns.structural.facade.model.Book;
import eu.jpereira.trainings.designpatterns.structural.facade.model.Customer;
import eu.jpereira.trainings.designpatterns.structural.facade.model.DispatchReceipt;
import eu.jpereira.trainings.designpatterns.structural.facade.model.Order;
import eu.jpereira.trainings.designpatterns.structural.facade.service.BookDBService;
import eu.jpereira.trainings.designpatterns.structural.facade.service.CustomerDBService;
import eu.jpereira.trainings.designpatterns.structural.facade.service.CustomerNotificationService;
import eu.jpereira.trainings.designpatterns.structural.facade.service.OrderingService;
import eu.jpereira.trainings.designpatterns.structural.facade.service.WarehouseService;




public class DefaultBookStoreFacade implements BookstoreFacade{

	private BookDBService bookService;
	private CustomerNotificationService customerNotificationService;
	private OrderingService orderingService;
	private CustomerDBService customerService;
	private WarehouseService warehouseService;
	
	public DefaultBookStoreFacade(BookDBService bookService, CustomerNotificationService customerNotifactionService, OrderingService orderingService, CustomerDBService customerService, WarehouseService wharehouseService)
	{
		this.bookService = bookService;
		this.customerNotificationService = customerNotifactionService;
		this.orderingService = orderingService;
		this.customerService = customerService;
		this.warehouseService = wharehouseService;
	}
	
	@Override
	public void placeOrder(String customerId, String isbn) {
		Customer c = customerService.findCustomerById(customerId);
		Book b = bookService.findBookByISBN(isbn);
		Order order = orderingService.createOrder(c, b);
		customerNotificationService.notifyClient(order);
		
		DispatchReceipt dispatchReceipt = warehouseService.dispatch(order);
		customerNotificationService.notifyClient(dispatchReceipt);
	}

}
